<script>
import {defineComponent} from 'vue'

export default defineComponent({
  name: "Count",
  data() {
    return {
      n: 1
    }
  },
  methods: {
    increment() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("increment", this.n)

      // this.$store.commit("ICCREMENT",this.n) 直接调用commit联系mutations
    },
    decrement() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("decrement", this.n)

      // this.$store.commit("DECREMENT",this.n) 直接调用commit联系mutations

    },
    incrementOdd() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("incrementOdd", this.n)

    },
    incrementWait() {
      //组件里面调用this.$store.dispatch(参数一：类型 参数二：值)联系actions
      this.$store.dispatch("incrementWait", this.n)

    },
  },

})
</script>
<template>
  <div>
    <h1>当前求和为:{{ this.$store.state.sum }}</h1>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="incrementOdd">求和为奇数再加</button>
    <button @click="incrementWait">等等再加</button>
  </div>
</template>

<style scoped lang="less">

</style>
